// services
import APIService from './api.service';
import qs from 'qs';

import type { ResponseData } from './types';

export type LoginInfo = {
  username: string;
  password: string;
  rememberMe: boolean;
};
const API_BASE_URL = import.meta.env.VITE_APP_BASE_URL;

/**
 * @description: 模型训练api
 * @return {*}
 */
class TrainService extends APIService {
  constructor() {
    super(API_BASE_URL);
  }

  async uploadTrainImage(params: any): Promise<ResponseData<any>> {
    return this.mediaUpload(`/web/web/user/uploadImg`, params)
      .then((response) => response?.data)
      .catch((error) => {
        throw error?.response?.data;
      });
  }

  async trainModel(params: any): Promise<ResponseData<any>> {
    return this.post(`/web/web/model/add`, params)
      .then((response) => response?.data)
      .catch((error) => {
        throw error?.response?.data;
      });
  }

  async getUserModelList(data: any): Promise<ResponseData<any>> {
    return this.get(`/web/web/model/pageModelNew?${qs.stringify(data)}`)
      .then((response) => response?.data)
      .catch((error) => {
        throw error?.response;
      });
  }

  async deleteModel(data: any): Promise<any> {
    return this.post(`/web/web/model/delModel?${qs.stringify(data)}`)
      .then((response) => response?.data)
      .catch((error) => {
        throw error?.response?.data;
      });
  }

  async useModel({ modelId }: any): Promise<ResponseData<any>> {
    return this.post(`/web/web/model/loadModel?modelId=${modelId}`)
      .then((response) => response?.data)
      .catch((error) => {
        throw error?.response?.data;
      });
  }

  async updateModel(data: any): Promise<ResponseData<any>> {
    return this.post(`/web/web/model/update`, data)
      .then((response) => response?.data)
      .catch((error) => {
        throw error?.response?.data;
      });
  }
}

export default new TrainService();
